console.log($event)
const gis = this.getApiPage().getApiWidgetByAliasName('三维组件')
if ($event.currentType === '详情') {
  gis.widgetObj.setIconPosition({ right: 420, top: 100 })
  gis.widgetObj.setModalPosition({ right: 815, bottom: 20 })
  gis.widgetObj.sullivan.initial()
  const { eventDetails, areaId } = $event.data
  this.pageObj.setVariables([{ 'name': 'areaId', 'value': areaId }])
  const detail = this.getApiPage().getApiWidgetsByClassName('detail')
  const wujing = this.getApiPage().getApiWidgetByAliasName('误警事件')
  const jiechu = this.getApiPage().getApiWidgetByAliasName('解除事件')
  const yanpan = this.getApiPage().getApiWidgetByAliasName('detail-judge')
  const guanbi = this.getApiPage().getApiWidgetByAliasName('关闭')
  const multipointLinkage = this.getApiPage().getApiWidgetsByClassName('multipoint_linkage');
  const linkVideo = this.getApiPage().getApiWidgetByAliasName('联动视频');
  const setFormSelect = this.getApiPage().getApiWidgetByAliasName('judge-content').widgetObj;
  setFormSelect.areaId = areaId
  multipointLinkage.forEach(v => v.hideWidget());

  this.getApiPage().getApiWidgetByAliasName('detail-save')?.hideWidget();
  this.getApiPage().getApiWidgetByAliasName('confirm')?.hideWidget();
  this.getApiPage().getApiWidgetByAliasName('cancel-event')?.hideWidget()
  this.getApiPage().getApiWidgetByAliasName('取消图标')?.hideWidget();


  detail.forEach(v => v.showWidget())

  function resetObj(obj, color, pointer) {
    $(obj.container).find('.label-text')[0].style.color = color
    obj.container.style.pointerEvents = pointer
  }

  try {
    if ($event.data.whetherProcess == '2') {
      resetObj(yanpan?.widgetObj, '#888', 'none');
      resetObj(wujing?.widgetObj, '#888', 'none');
    } else if ($event.data.whetherProcess == '0') {
      resetObj(yanpan?.widgetObj, '#FFF', 'auto');
      resetObj(wujing?.widgetObj, '#FFF', 'auto');
      resetObj(jiechu?.widgetObj, '#FFF', 'auto');
    } else if ($event.data.whetherProcess == '4' || $event.data.whetherProcess == '1') {
      wujing.hideWidget()
      jiechu.hideWidget()
      yanpan.hideWidget()
      guanbi.hideWidget()
      linkVideo.hideWidget()
    } else if ($event.data.whetherProcess == '3') {
      resetObj(yanpan?.widgetObj, '#888', 'none');
      resetObj(wujing?.widgetObj, '#888', 'none');
      resetObj(jiechu?.widgetObj, '#888', 'none');
    }
  } catch (error) {
    console.error(error)
  }


  const $form = this.getApiPage().getApiWidgetByAliasName('judge-content');
  const $img = this.getApiPage().getApiWidgetByAliasName('detail-img');
  $event.data.eventPoint = $event.data.xCoordinate + '，' + $event.data.yCoordinate + '，' + $event.data.zCoordinate;
  const formData = {
    ...$event.data,
  }
  // 详情时隐藏上传功能
  $form.widgetObj._option.config.forEach(v => {
    if (v.type == 'upload') {
      v.visible = true
    }
    if (v.dataIndex == 'sourceDeviceId') {
      v.visible = true
    }
  })
  $form.widgetObj._option.dataSource = formData;
  $form.widgetObj._option.isDetail = true;
  $form.widgetObj.render();
  const form = this.getApiPage().retrievePlugin('base-forms');
  const $playback = this.getApiPage().getApiWidgetByAliasName('playback')
  form.resetForm('form_14')
  form.resetForm('form_20')
  // form.setFormData('form_14', $event.data)
  const info = JSON.parse(eventDetails)
  if (Object.keys(info).length !== 0) {
    if (info.thumbnailPath) {
      const srcArr = info?.thumbnailPath.split(',').map(v => ({ src: v }))
      $img.widgetObj.setData([{ data: srcArr }])
      $img.widgetObj.render()
    } else {
      $img.widgetObj.setData([{ data: [] }])
      $img.widgetObj.render();
    }

    if (info?.jpbPath) {
      // 打开回放
      $playback.widgetObj.setData([{ data: info?.jpbPath }])
      $playback.showWidget();
      $playback.widgetObj.render();
    } else {
      $playback.hideWidget();
      window.layer.msg('暂无录像回放')
    }
  } else {
    $img.widgetObj.setData([{ data: [] }])
    $img.widgetObj.render();

    $playback.hideWidget();
    window.layer.msg('暂无录像回放')
  }

  if ($event.data.sourceDeviceId) {
    // 打开实时视频
    const options = {
      method: 'GET',
      headers: {
        "Content-type": "application/json",
      },
    }
    fetch(`/Basics/basics-main/system/equipmentObject/listDetailByEquipmentCode?equipmentCode=${$event.data.sourceDeviceId}`, options)
      .then(res => res.json())
      .then(json => {
        if (json?.success && json.result) {
          const { rows } = json.result
          const data = rows[0]?.equipmentConfig?.gbVideoConfig
          var host = this.getApiPage().getVariables().find(x => x.name == "stream_url").value;
          gis.widgetObj.sullivan.close()
          gis.widgetObj.sullivan.initial()
          if (data && data.sipUser && data.videoChannelId) {
            gis.widgetObj.sullivan.addPlayer(`${host}/api/v1/stream/rtc/play`, `${data.sipUser}/${data.videoChannelId}`)
          } else {
            window.layer.msg('暂无设备号/通道号')
          }
        }
      })
  } else {
    gis.widgetObj.sullivan.close();
    window.layer.msg('未关联摄像头');
  }

} else if ($event.currentType === '定位') {
  console.log('定位', $event.data)
  const params = {
    ...$event.data,
  }
  if (!params.xCoordinate) {
    params.xCoordinate = 106.666980
  }
  if (!params.yCoordinate) {
    params.yCoordinate = 29.487431
  }
  if (!params.zCoordinate) {
    params.zCoordinate = 6.37
  }
  gis.widgetObj.gisMap.setEvent(params);

} else if ($event.currentType === '处置') {
  window.parent.postMessage({ type: 'nav/style', pageName: '处置' }, document.referrer);
  var authTokenVar = this.getApiPage().getVariables().find(x => x.name == "AuthToken");
  this.getApiPage().navigateStage('759726721858535424', [{ name: 'screen_params', value: $event.data }, { name: 'AuthToken', value: authTokenVar.value }])
} else if ($event.currentType === '记录') {
  const timeline = this.getApiPage().getApiWidgetByAliasName('timelineVertical');
  const summary = this.getApiPage().getApiWidgetByAliasName('summary')
  summary.hideWidget();

  if (timeline && timeline.widgetObj) {
    const { setUpdateStatus, setVariable } = timeline.widgetObj

    if (setUpdateStatus) setUpdateStatus($event.data.whetherProcess !== 1);
    if (setVariable) setVariable('timeline_event_id', $event.data.id);
  }

  timeline.showWidget()

  window.parent.postMessage({ type: 'nav/style', pageName: '记录' }, document.referrer);
} else if ($event.currentType === '总结') {
  const timeline = this.getApiPage().getApiWidgetByAliasName('timelineVertical');
  const summary = this.getApiPage().getApiWidgetByAliasName('summary').widgetObj;
  timeline.hideWidget()
  this.pageObj.setVariables([{ name: 'timeline_event_id', value: $event.data.id }])
  summary.show()
  $('#summary .file-box').text(summary.fileName)

  window.parent.postMessage({ type: 'nav/style', pageName: '总结' }, document.referrer);

} else if ($event.currentType === '合并事件') {
  const merge_modals = this.pageObj.getApiWidgetsByClassName('event-merge')
  const eventTime = this.pageObj.getApiWidgetsByClassName('event-time');
  merge_modals.forEach(v => v.showWidget())
  eventTime.forEach(v => v.hideWidget());
} else if ($event.currentType === '发生时间列表') {
  const eventTime = this.pageObj.getApiWidgetsByClassName('event-time');
  const merge_modals = this.pageObj.getApiWidgetsByClassName('event-merge');
  merge_modals.forEach(v => v.hideWidget());
  eventTime.forEach(v => v.showWidget());

  this.pageObj.setVariables([{ name: 'event_parentId', value: $event.data.id }])
}